﻿Imports FlickrNet
Public Class Form1
    Const apikey As String = "4c76c1d6d9f89d179375bcf37cdf97ec"
    Const secret As String = "255c0c5e2e711533"
    Private tempFrob As String
    Private strFlickrToken As String
    Private a As Auth
    Private f As Flickr
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            strFlickrToken = GetSetting("FlickrWhoIs", "Authentication", "AuthToken")
            If Len(strFlickrToken) = 0 Then
                ' Get Frob    
                tempFrob = f.AuthGetFrob()
                ' Calculate the URL at Flickr to redirect the user to
                Dim flickrUrl As String = f.AuthCalcUrl(tempFrob, AuthLevel.Write)
                ' The following line will load the URL in the users default browser.
                System.Diagnostics.Process.Start(flickrUrl)
                a = f.AuthGetToken(tempFrob)
                strFlickrToken = a.Token
                SaveSetting("FlickrWhoIs", "Authentication", "AuthToken", strFlickrToken)
            Else
                f = New Flickr(apikey, secret, strFlickrToken)
                MsgBox(f.IsAuthenticated, MsgBoxStyle.Information)
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub cmdListContacts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdListContacts.Click
        lstContacts.Clear()
        Dim contactList As Contacts
        lstContacts.GridLines = True
        'Dim lContact As Contact
        contactList = f.ContactsGetList
        lstContacts.View = View.Details

        Try
            lstContacts.Columns.Add("UserId", 80, HorizontalAlignment.Left)
            lstContacts.Columns.Add("UserName", 200, HorizontalAlignment.Right)

            For x = 1 To contactList.ContactCollection.Count - 1
                Dim str(2) As String
                str(0) = contactList.ContactCollection(x).UserId
                str(1) = contactList.ContactCollection(x).UserName
                Dim colItem As New ListViewItem(str)
                lstContacts.Items.Add(colItem)

                'Dim colUserId As New ListViewItem(contactList.ContactCollection(x).UserId)
                'Dim colUserName As New ListViewItem(contactList.ContactCollection(x).UserName)
                'lstContacts.Items.AddRange(New ListViewItem() {colUserId, colUserName})
                'lstContacts.Columns("colUserId").Text = contactList.ContactCollection(x).UserId
                'lstContacts.Columns("colUserName").Text = contactList.ContactCollection(x).UserName
                'lstContacts.Items.Add(contactList.ContactCollection(x).UserId & vbTab & contactList.ContactCollection(x).UserName)
            Next x
        Catch ex As Exception
            Debug.Print(ex.ToString)
        End Try
    End Sub

    Private Sub cmdDemo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDemo.Click

        ' Set the view to show details.
        lstContacts.View = View.Details
        ' Allow the user to edit item text.
        lstContacts.LabelEdit = True
        ' Allow the user to rearrange columns.
        lstContacts.AllowColumnReorder = True
        ' Display check boxes.
        lstContacts.CheckBoxes = True
        ' Select the item and subitems when selection is made.
        lstContacts.FullRowSelect = True
        ' Display grid lines.
        lstContacts.GridLines = True
        ' Sort the items in the list in ascending order.
        lstContacts.Sorting = SortOrder.Ascending

        ' Create three items and three sets of subitems for each item.
        Dim item1 As New ListViewItem("item1", 0)
        ' Place a check mark next to the item.
        item1.Checked = True
        item1.SubItems.Add("1")
        item1.SubItems.Add("2")
        item1.SubItems.Add("3")
        Dim item2 As New ListViewItem("item2", 1)
        item2.SubItems.Add("4")
        item2.SubItems.Add("5")
        item2.SubItems.Add("6")
        Dim item3 As New ListViewItem("item3", 0)
        ' Place a check mark next to the item.
        item3.Checked = True
        item3.SubItems.Add("7")
        item3.SubItems.Add("8")
        item3.SubItems.Add("9")

        ' Create columns for the items and subitems.
        lstContacts.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
        lstContacts.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
        lstContacts.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
        lstContacts.Columns.Add("Column 4", -2, HorizontalAlignment.Center)

        'Add the items to the ListView.
        lstContacts.Items.AddRange(New ListViewItem() {item1, item2, item3})

        ' Create two ImageList objects.
        Dim imageListSmall As New ImageList()
        Dim imageListLarge As New ImageList()

        ' Initialize the ImageList objects with bitmaps.
        imageListSmall.Images.Add(Bitmap.FromFile("d:\user\ab_face.jpg"))
        imageListSmall.Images.Add(Bitmap.FromFile("d:\user\ab_face.jpg"))
        imageListLarge.Images.Add(Bitmap.FromFile("d:\user\ab_face.jpg"))
        imageListLarge.Images.Add(Bitmap.FromFile("d:\user\ab_face.jpg"))

        'Assign the ImageList objects to the ListView.
        lstContacts.LargeImageList = imageListLarge
        lstContacts.SmallImageList = imageListSmall

    End Sub
End Class
